﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mvc_monday.Models;

namespace mvc_monday.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            // try to render to the data to the view....
            // 1 - create the VM
            EmployeeIndexVm IndexVm = new EmployeeIndexVm();

            // 2 - populate the VM
            IndexVm.WelcomeMessage = "Welcome dear employees";
            IndexVm.MyEmployees = DataHolder.FetchData();


            // Instatiated a new Area51VM
            IndexVm.PartialVm = new Area51Vm();
            IndexVm.PartialVm.Area51Welcome = "Hello from the PARTIAL!!!!!!!!!!!!!!";

            // The login VM
            IndexVm.LoginVm = new LoginVm();
            IndexVm.LoginVm.BtnTitle = "Please log in!";

            // 2.1 pass VM into the view
            // VIEW...
            //      3 - foreach
            //      4 - table
            return View(IndexVm);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult Details(int id)
        {
            DetailsVm myVm = new DetailsVm();
            var tempId = id;
            myVm.identification = id;
            List<Employee> tData = DataHolder.FetchData();
            //var results = tData.Where(e => e.EmployeeId == tempId).ToList();
            
            var results = tData.Where(e => e.Type == EmployeeTypes.Manager).ToList();
            
            myVm.myList = results;
            return View(myVm);
        }

    }

    // Mock data class...
    public static class DataHolder {

        // method to return Mock data..
        public static List<Employee> FetchData()
        {
            List<Employee> data = new List<Employee>()
            {
                new Employee(){Type = EmployeeTypes.Employee, FirstName="Rick", LastName="James", Salary=35.000, EmployeeId=123 },
                new Employee(){Type = EmployeeTypes.Employee, FirstName="Bobby", LastName="Brown", Salary=25.000, EmployeeId=124 },
                new Manager(){Type = EmployeeTypes.Manager, FirstName="Withney", LastName="Dallas", Salary=99.00, EmployeeId=555, Device="Blackberry" },
                new Manager(){Type = EmployeeTypes.Manager, FirstName="Brittney", LastName="Spears", Salary=95.00, EmployeeId=556, Device="Pager" },
                new Supervisor(){Type = EmployeeTypes.Supervisor,  FirstName="Mike", LastName="Tyson", Salary=199.00, EmployeeId=655, Device="Ipad", Territory="West Coast" }
 
            };

            return data;
        }

    }

}